package org.lvgo.abstractfactory;

/**
 * Hello world!
 *
 * @author lvgo
 */
public class App {

    public static void main(String[] args) {
        KingdomFactory elfKingdomFactory = FactoryMaker.makeFactory(FactoryMaker.KingdomType.ELF);
        Army elfArmy = elfKingdomFactory.createArmy();
        System.out.println(elfArmy.getDescription());
        Castle elfCastle = elfKingdomFactory.createCastle();
        System.out.println(elfCastle.getDescription());
        King elfKing = elfKingdomFactory.createKing();
        System.out.println(elfKing.getDescription());

        KingdomFactory orcKingdomFactory = FactoryMaker.makeFactory(FactoryMaker.KingdomType.ORC);
        Army orcArmy = orcKingdomFactory.createArmy();
        System.out.println(orcArmy.getDescription());
        Castle orcCastle = orcKingdomFactory.createCastle();
        System.out.println(orcCastle.getDescription());
        King orcKing = orcKingdomFactory.createKing();
        System.out.println(orcKing.getDescription());

    }


    public static class FactoryMaker {
        public static KingdomFactory makeFactory(KingdomType type) {
            switch (type) {
                case ELF:
                    return new ElfKingdomFactory();
                case ORC:
                    return new OrcKingdomFactory();
                default:
                    throw new IllegalArgumentException("KingdomType not supported.");
            }
        }

        public enum KingdomType {
            /**
             * 精灵
             */
            ELF,
            /**
             * 兽人
             */
            ORC
        }
    }
}



